package com.itstyle.seckill.common.algorithm;

public class test {
    public static void main(String[] args) {
        int[] arr = {10,7,2,4,7,62,3,4,2,1,8,9,19};
        quickSort(arr, 0, arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+":");
        }
    }

    /**
     * 快速排序
     */
    public static void quickSort(int[] arr,int low ,int high){
        int i,j,temp,t;
        if(low > high){
            return;
        }
        i = low;
        j = high;
        //temp 是基准位置
        temp = arr[low];
        while(i < j){
            while(i < j && arr[j] >= temp){
                j--;
            }
            while(i < j && arr[i] <= temp){
                i++;
            }
            if(i < j){
                t = arr[j];
                arr[j] = arr[i];
                arr[i] = t;
            }
        }
        //交换基准位置和相等位置
        arr[low] = arr[i];
        arr[i] = temp;
        quickSort(arr,low,i-1);
        quickSort(arr,i+1,high);
    }
}
